package cn.wp.common.core;

import cn.wp.common.core.web.WpWebMvcConfigurer;
import cn.wp.common.core.web.client.LoadBalanceRestTemplate;
import cn.wp.common.core.web.client.ServiceTemplate;
import cn.wp.common.core.web.client.SimpleRestTemplate;
import cn.wp.common.core.web.service.ServiceConfigurations;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 框架默认配置类
 * Created by chenyb on 2019-09-24
 */
@Configuration
public class WpConfiguration {

    @Bean
    public Wp wpInstance(){
        Wp wp = new Wp();
        wp.instance(wp);
        return wp;
    }

    @Bean
    @Order(-1)
    public WebMvcConfigurer webMvcConfigurer(){
        return new WpWebMvcConfigurer();
    };


    @Bean
    public ServiceConfigurations serviceConfigurations(){
        return new ServiceConfigurations();
    }

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public SimpleRestTemplate simpleRestTemplate(){
        return new SimpleRestTemplate();
    }

    @Bean
    @LoadBalanced
    public LoadBalanceRestTemplate loadBalanceRestTemplate(){
        return new LoadBalanceRestTemplate();
    }

    @Bean
    public ServiceTemplate serviceTemplate(){
        return new ServiceTemplate();
    }

    /*@Bean
    public FilterRegistrationBean corsFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CorsFilter());
        registration.addUrlPatterns("/*");
        //registration.setOrder(1);
        return registration;
    }*/

}